<template slot-scope="scope">
    <div class="index">
        <el-card class="box-card font-left">
            <div slot="header" class="clearfix">
                <span>已有频道</span>
                <el-button style="margin-left: 500px"  type="primary" @click="handleAdd">创建频道</el-button>
                <el-dialog title="创建新频道" :visible.sync=prompt class="box-card font-left">
                        <el-form ref="form" :model="form" label-width="80px">
                        <el-form-item label="频道名称">
                            <el-input v-model="form.channelName"></el-input>
                        </el-form-item>
                        <el-form-item label="创建人" >
                            <el-input v-model="form.creater" readonly></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="onSubmit(form)">立即创建</el-button>
                            <el-button @click="prompt=false">取消</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>
            </div>
                <el-table
                    :data="tableData"
                    style="width: 100%">
                    <el-table-column
                    label="创建日期"
                    width="180">
                    <template slot-scope="scope">
                        <i class="el-icon-time"></i>
                        <span style="margin-left: 10px">{{ scope.row.CTime }}</span>
                    </template>
                    </el-table-column>
                    <el-table-column
                    label="操作人"
                    width="180">
                    <template slot-scope="scope">
                        <span style="margin-left: 10px">{{ scope.row.user.Count }}</span>
                    </template>                       
                    </el-table-column>
                    <el-table-column
                    label="nav"
                    width="180">
                    <template slot-scope="scope">
                        <span style="margin-left: 10px">{{ scope.row.Tile }}</span>
                    </template>                       
                    </el-table-column>
                    <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button
                        size="mini"
                        @click="handleEdit(scope.row)">编辑</el-button>                       
                            <el-dialog title="已有频道编辑" :visible.sync=dialogFormVisible class="el-card">
                                    <el-form :model="form">
                                        <el-form-item :label-width="formLabelWidth">
                                            <el-input v-model="form.NAID" type="hidden"></el-input>
                                        </el-form-item>                                        
                                        <el-form-item label="创建时间" :label-width="formLabelWidth">
                                            <el-input v-model="form.CTime" disabled></el-input>
                                        </el-form-item>
                                        <el-form-item label="操作人" :label-width="formLabelWidth" >
                                            <el-input v-model="form.user.Count" disabled></el-input>
                                        </el-form-item>
                                        <el-form-item label="nav名称" :label-width="formLabelWidth">
                                            <el-input v-model="form.Tile"></el-input>
                                        </el-form-item>
                                    </el-form>
                                    <div slot="footer" class="dialog-footer">
                                        <el-button @click="dialogFormVisible = false">取 消</el-button>
                                        <el-button type="primary" @click="Edited(form)">确 定</el-button>
                                    </div>
                            
                            </el-dialog>
                                                               
                        <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.row)">删除</el-button>
                            <el-dialog
                            title="提示"
                            :visible.sync="notice"
                            width="30%"
                           >
                            <span>确认删除Nav：{{tableDate2.Tile}}？</span>
                            <span slot="footer" class="dialog-footer">
                                <el-button @click="notice = false">取 消</el-button>
                                <el-button type="primary" @click="delet(tableDate2)">确 定</el-button>
                            </span>
                            </el-dialog>
                    </template> 
                    </el-table-column>
                </el-table> 
        </el-card>
    </div>
</template>

<script>

    export default {
        data() {
            return {
                tableData:[],
                dialogFormVisible :false,
                notice:false,//删除提示
                prompt:false,//增加提示
                formLabelWidth:'120px',
                form:{
                    NAID:'',
                    CTime:'',
                    user:{
                        Count:'',
                        UID:''
                    },
                    Tile:'',
                    channelName: '',
                    creater: this.$store.state.userInfo.count,
                    desc: ''
                },
                tableDate2:{}
            }
        },
        methods: {
            handleEdit(row) {
                this.form = row
                this.dialogFormVisible=true;
            },
            //删除再确认
            handleDelete(row) {
                this.notice=true;
                this.tableDate2 = row
            },
            handleAdd() {
                this.prompt=true;
                // this.form1=a;
            },
            //创建按钮触发
            onSubmit(form){
                this.prompt=false;
                this.$axios.post("/Nav/addNav",{Tile:form.channelName,UID:this.$store.state.userInfo.UID}).then(res=>{
                    const result = res.data.d;
                    if(result.status==false){
                        return this.$message.error(result.message);
                    }
                    this.$message.success(result.message);
                    //再次请求刷新页面
                    this.$axios.post("/Nav/search").then(res=>{
                        this.tableData = res.data.d.L
                        })                    
                    this.$message.success(result.message)
                })
            },
            //确认按钮触发
            delet(form){
                this.notice=false;
                this.$axios.post("/Nav/deleteNav",form).then(res=>{
                   const result = res.data.d;
                   if(result.status==false){
                       return this.$message.error(result.message)
                   }
                  //再次请求刷新页面
                this.$axios.post("/Nav/search").then(res=>{
                    this.tableData = res.data.d.L
                })                    
                   this.$message.success(result.message)
                })
            },
            Edited(form){
                form.user.UID = this.$store.state.userInfo.UID
                this.dialogFormVisible = false
                this.$axios.post("/Nav/updateNav",form).then(res=>{
                  const result = res.data.d;
                  if(result.status==false){
                      return this.$message.error(result.message)
                  }
                  //再次请求刷新页面
                this.$axios.post("/Nav/search").then(res=>{
                    this.tableData = res.data.d.L
                })                  
                this.$message.success(result.message)
                })                
            }
        },
        mounted(){
            //初始化页面
           this.$axios.post("/Nav/search").then(res=>{
               this.tableData = res.data.d.L
           }) 
        }
    }
</script>

<style scoped>
    .box-card{
        margin: 5% 5%
    }
    .el-table{
        margin:3% 3%
    }
    .font-left{
        text-align:left;
        font-weight:bold
    }
    .font-right{
        margin-left: 500px;
    }
</style>